<?php
/**
* wangtao5@
* 获取数据的接口
*/
class ml_tool_getdata
{
    private static $_configs;
    private static $_verson_path;
    static function get_configs($name,$dir){
        if(empty($dir))
            $data = self::$_configs['lb_rsync'][$name];
        else
            $data = self::$_configs['lb_rsync'][$dir][$name];
        return $data;
    }
    
    static function set_configs($name,$dir,$data){
        if(empty($dir))
            self::$_configs['lb_rsync'][$name] = $data;
        else
            self::$_configs['lb_rsync'][$dir][$name] = $data;
        return true;
    }
    
    static function jsonData($type, $name, $dir=''){ 
        $data = self::get_configs($name, $dir);
        if(isset($data))
            return $data;
        $path = str_replace('//', '/', SYSDEF_PRIVDATA_ROOT_PATH.'/'.$type.'/'.$dir.'/');
        $path .= $name.'.json';
        
        if(!is_file($path)){
            $data = false;
        }else{
            $data = json_decode(file_get_contents($path), true);
        }
        self::set_configs($name, $dir, $data);
        
        return $data;
    }
    static function lbJsonData($name, $dir=''){ //lb_rsync
        return self::jsonData('lb_rsync', $name, $dir);
    }
    static function mlJsonData($name, $dir=''){ //ml_rsync
        return self::jsonData('ml_rsync', $name, $dir);
    }
    
    static function lmJsonData($name, $dir=''){ //guang_data
        return self::jsonData('guang_data', $name, $dir);
    }
    
    static function riaVersion($path){
        if(!empty(self::$_verson_path[$path]))
            return self::$_verson_path[$path];
        
        $content = self::mlJsonData('ria_version');
        $ext = strrchr($path, '.');
        if(!$content){
            $version = ML_RIA_DEFAULT_VERSION;
        }else{
            $ext_array = array('js'=>'js','css'=>'css','png'=>'images','gif'=>'images');
            $type = $ext_array[trim($ext, '.')];
            $version = $content[$type][$path];
            
            if(empty($version))
                $version = ML_RIA_DEFAULT_VERSION;
        }
        $new_path = str_replace($ext, '.'.$version.$ext, $path);
        self::$_verson_path[$path]= $new_path;
        return $new_path;
    }
    
}
?>